<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>底部导航</title>
    <script type="text/javascript" src="script/config.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/api.css"/>
    <link rel="stylesheet" type="text/css" href="./css/style.css"/>
    <style>
        header{ background-color: #f16c3c; }
        header ul li { height: 50px; line-height: 50px; text-align: center; display: none; color: #323237; position: relative;font-size: 18px;color:white;}
        header ul li.active{ display: block; }
        #footer{  background-color: #f2f2f2; }
        #footer ul li{  padding-top: 36px; padding-bottom: 4px; background: url() no-repeat center 5px; background-size: auto 30px; text-align: center;}
        #footer ul li.active{ color: #f16c3c; }
        #footer ul li:nth-child(1){ background-image: url(./image/homepage2.png);}
        #footer ul li:nth-child(2){ background-image: url(./image/vehicle1.png); }
        #footer ul li:nth-child(3){ background-image: url(./image/person_information1.png); }
        /*#footer ul li:nth-child(4){ background-image: url(./image/bottombtn0401.png); }*/
        #footer ul li:nth-child(1).active{ background-image: url(./image/homepage1.png); }
        #footer ul li:nth-child(2).active{ background-image: url(./image/vehicle2.png); }
        #footer ul li:nth-child(3).active{ background-image: url(./image/person_information2.png); }
        /*#footer ul li:nth-child(4).active{ background-image: url(./image/bottombtn0402.png); }*/
        .flex-con{
          overflow: auto
        }
    </style>
</head>
<body>
<div id="wrap" class="flex-wrap flex-vertical">
    <header>
        <ul>
            <li class="border-b active" >我的主页</li>
            <li class="border-b" >车辆管理</li>
            <li class="border-b" >我的资料</li>
            <!-- <li class="border-b" >文档</li> -->
        </ul>
    </header>
    <div id="main" class="flex-con">
    </div>
    <div id="footer" class="border-t">
        <ul class="flex-wrap" >
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con active" >我的主页</li>
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" id="app_lorry">车辆管理</li>
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" >我的资料</li>
            <!-- <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" >文档</li> -->
        </ul>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript" src="script/local.js"></script>
<script type="text/javascript" src="script/up_check.js"></script>
<script type="text/javascript">
    apiready = function(){
var index22=0;
var yingxiang = 0;
yingxiang=$api.getStorage('yingxiang');
if(yingxiang==1){
index22=1;
randomSwitchBtn($api.dom('#app_lorry'));
$api.rmStorage('yingxiang');
$api.setStorage('yingxiang', 0);
}


if (api.systemType == "ios") {
      api.addEventListener({
       name:'pause'
     }, function(ret, err){

       api.closeWidget({
               silent : true
       });

    });
    }

    // var isAndroid = (/android/gi).test(navigator.appVersion);
    //
    // api.addEventListener({
    //     name:'pause'
    // },function(ret,err){
    //   if (isAndroid) {
    //       var rb = api.require('runBackground');
    //       rb.hideActivity();
    //   }
    // });

      // checkUpdate();
      api.closeToWin({name:'main'});
      var pressIndex=0;
      api.addEventListener({
                              name : 'keyback'
                      }, function(ret, err) {
                              pressIndex++;
                              api.toast({
                                      msg : '再按一次退出应用',
                                      duration : 1000,
                                      location : 'middle'
                              });
                              setTimeout(function() {
                                      pressIndex = 0;
                              }, 1000);
                              if (pressIndex >= 2) {
                                  // api.toLauncher();
                                  var rb = api.require('runBackground');
                                 rb.hideActivity();
                              }
                      });


      setInterval(addEventListener,3000);
      var user = $api.getStorage('user');
      var lorryid=user.lorryid;
      var time=user.time;

      upload_map(lorryid);
      setInterval("upload_map("+lorryid+")",5000);
      api.addEventListener({
                            name:'viewappear'
                        }, function(ret, err){
                           api.setScreenOrientation({
                            orientation: 'portrait_up'
                        });
                        });
        $api.fixStatusBar( $api.dom('header') );
        api.setStatusBarStyle({
            style: 'light',
            color: '#333333'
        });
        // alert(index22)
        funIniGroup(index22);


    }

    function funIniGroup(index1){

        var eHeaderLis = $api.domAll('header li'),
            frames = [];
        for (var i = 0,len = eHeaderLis.length; i < len; i++) {
                frames.push( {
                    name: 'frame'+i,
                    url: './html/frame'+i+'.html',
                    bgColor : 'rgba(0,0,0,.2)',
                    bounces:true
                } )
        }
        api.openFrameGroup({
            name: 'group',
            scrollEnabled: false,
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight,
                w: api.winWidth,
                h: $api.dom('#main').offsetHeight
            },
            index:index1,
            preload:3,
            frames: frames
        }, function (ret, err) {

        });
    }

    // 随意切换按钮
    function randomSwitchBtn( tag ) {
      var user = $api.getStorage('user');
      var lorryid=user.lorryid;
      var time=user.time;
      check(lorryid,time);
        if( tag == $api.dom('#footer li.active') )return;
        var eFootLis = $api.domAll('#footer li'),
            eHeaderLis = $api.domAll('header li'),
            index = 0;
        for (var i = 0,len = eFootLis.length; i < len; i++) {
            if( tag == eFootLis[i] ){
                index = i;
            }else{
                $api.removeCls(eFootLis[i], 'active');
                $api.removeCls(eHeaderLis[i], 'active');
            }
        }
        $api.addCls( eFootLis[index], 'active');
        $api.addCls( eHeaderLis[index], 'active');
        api.setFrameGroupIndex({
            name: 'group',
            index: index,
            reload:true,
        });
    }
    var upload_map=function(id){
      // alert(1)
      var bMap = api.require('bMap');
      bMap.getLocation({
          accuracy: '10m',
          autoStop: true,
          filter: 1
      }, function(ret, err) {
          if (ret.status) {
            $api.post(url+'app.php/scmap',{
             body:{
                  lorryid:id,
                  longitude:ret.lon,
                  latitude:ret.lat,
                  }
             },function(ret){
            //  alert(ret.desc);
           },'json');
          } else {
              // alert(err.code);
          }
      });
    }
    function addEventListener(){
    api.addEventListener({
            name:'offline'
          },function(ret,err){
            var connectionType = ret.connectionType;
            // api.alert({
            //   title: '提示消息',
            //   msg: '当前网络不可用，请检查网络设置',
            //   buttons: ['确定']
            // });
            api.openWin({
              name: 'false',
              url:  './false.html',
              slidBackEnabled:false,
            });
            setTimeout("api.closeWin({name:'main'})",600);
            //  Jurl="false.html";
          });

    }

    // function checkUpdate() {
    //             var mam = api.require('mam');
    //             mam.checkUpdate(function(ret, err) {
    //                 if (ret) {
    //                     var result = ret.result;
    //                     if (result.update == true && result.closed == false) {
    //                         var str = '新版本型号:' + result.version + ';更新提示语:' + result.updateTip + ';下载地址:' + result.source + ';发布时间:' + result.time;
    //                         api.confirm({
    //                             title : '有新的版本,是否下载并安装 ',
    //                             msg : str,
    //                             buttons : ['确定', '取消']
    //                         }, function(ret, err) {
    //                             if (ret.buttonIndex == 1) {
    //                                 if (api.systemType == "android") {
    //                                     api.download({
    //                                         url : result.source,
    //                                         report : true
    //                                     }, function(ret, err) {
    //                                         if (ret && 0 == ret.state) {
    //                                           api.showProgress({
    //                                               title: '更新中...',
    //                                               text: '先喝杯茶，正在下载应用',
    //                                               modal: true
    //                                              });
    //
    //                                             // api.toast({
    //                                             //     msg : "正在下载应用" + ret.percent + "%",
    //                                             //     duration : 2000
    //                                             // });
    //                                         }
    //                                         if (ret && 1 == ret.state) {
    //                                             var savePath = ret.savePath;
    //                                             api.installApp({
    //                                                 appUri : savePath
    //                                             });
    //                                         }
    //                                     });
    //                                 }
    //                                 if (api.systemType == "ios") {
    //                                     api.installApp({
    //                                         appUri : result.source
    //                                     });
    //                                 }
    //                             }
    //                         });
    //                     } else {
    //                         // api.alert({
    //                         //     msg : "暂无更新"
    //                         // });
    //                     }
    //                 } else {
    //                     // api.alert({
    //                     //     msg : err.msg
    //                     // });
    //                 }
    //             });
    //         }


</script>
